package com.example.browseimagedemo

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import com.example.browseimagedemo.ui.theme.BrowseImageDemoTheme
import net.engawapg.lib.zoomable.rememberZoomState
import net.engawapg.lib.zoomable.zoomable

class MainActivity : ComponentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      BrowseImageDemoTheme {
        // A surface container using the 'background' color from the theme
        Surface(
          modifier = Modifier.fillMaxSize(),
          color = MaterialTheme.colorScheme.background
        ) {
          GalleryZoomable()
        }
      }
    }
  }
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun GalleryZoomable() {
  HorizontalPager(
    state = rememberPagerState(pageCount = {10})
  ) {
    val painter = painterResource(id = R.drawable.pig)
    val zoomState = rememberZoomState(maxScale = 10f, contentSize = painter.intrinsicSize)
    Image(
      painter = painter,
      contentDescription = null,
      contentScale = ContentScale.Fit,
      modifier = Modifier
        .fillMaxSize()
        .zoomable(zoomState)
    )
  }
}


@OptIn(ExperimentalFoundationApi::class)
@Composable
fun Gallery() {
  HorizontalPager(
    state = rememberPagerState(pageCount = {10})
  ) {
    Box {
      ImageView()
      Text(text = "$it", color = Color.White)
    }
  }
}

